import nav from "./nav.json"
import list from "./list.json"
import type {MockMethod} from "vite-plugin-mock";
import success from "../success.json"
import authority from "./authority.json"
import {findItemById} from "../utils";


export default [
    {
        url: "/menu/nav",
        method: "post",
        response: () => {
            return nav;
        }
    },
    {
        url: "/menu/list",
        method: "post",
        response: () => {
            return list;
        }
    },
    {
        url: "/menu/detail",
        method: "get",
        response: ({query}: any) => {
            //console.log(query.id);
            let info = findItemById(list.data, query.id, "menuId");
            let infoResult = null;
            if (info) {
                infoResult = JSON.parse(JSON.stringify(info));
            }
            if (info && info.children) {
                infoResult.children = null;
            }
            let result = JSON.parse(JSON.stringify(success));
            // @ts-ignore
            result.data = infoResult;
            return result;
        }
    },
    {
        url: "/menu/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/menu/authority",
        method: "get",
        response: () => {
            return authority;
        }
    },
    {
        url: "/menu/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    },
] as MockMethod[];
